﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using ForkCarRelationManager.db;
using ForkCarRelationManager.Utility;
using ForkCarRelationManager.Business;
namespace ForkCarRelationManager
{
    public partial class addfearForm : Form
    {
        dbOperate dbo = new dbOperate();
        MaintenBI maintenBI = new MaintenBI();
        Util util = new Util();
        private int maintenID=0;
        public addfearForm(int maintenID)
        {
            this.maintenID = maintenID;
            InitializeComponent();
        }

        private void addfearForm_Load(object sender, EventArgs e)
        {

        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
           
            if (TBName.Text.Trim() == ""  || TBunitprice.Text.Trim() == "" || TBcount.Text.Trim() == "")
            {
                MessageBox.Show("名字,单价,数量不能为空");
            }
            else
            {
              string  name = TBName.Text.Trim();
              string standard = TBStandard.Text.Trim();
              string unit = TBunit.Text.Trim();
              string count = TBcount.Text.Trim();
              string unitprice = TBunitprice.Text.Trim();
              string remark=Remark.Text.Trim();
              if (!util.isnumeric(count) || !Regex.IsMatch(unitprice, @"^[+-]?\d*[.]?\d*$") || name.Trim() == "")
              {
                  MessageBox.Show("名称不能为空，且数量,单价必须为数字");
                  
              }
              else
              {
                  double punitprice = Convert.ToDouble(unitprice);
                  punitprice = Math.Round(punitprice, 2);
                  int pcount = Convert.ToInt32(count);

                  double price = punitprice * (double)pcount;
                  if (maintenBI.addmaintenpartInfor(name, standard, pcount, unit, punitprice, price, remark, maintenID))
                  {
                      MessageBox.Show("添加成功");
                      this.DialogResult = DialogResult.Yes;
                  }
              }
            }
            
        }
    }
}
